package com.xsz.order.controller;

import com.xsz.common.controller.BaseController;
import com.xsz.common.domain.ResponseBo;
import com.xsz.order.domain.CreateOrderForm;
import com.xsz.order.domain.QueryOrderForm;
import com.xsz.order.domain.UpdateOrderForm;
import com.xsz.order.entity.Order;
import com.xsz.order.enums.OrderStatus;
import com.xsz.order.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.EnumSet;
import java.util.Objects;

/**
 * @author zsj55    
 */
@RestController
@RequestMapping("order")
public class OrderController extends BaseController {
    @Resource
    private OrderService orderService;

    @PostMapping("createOrder")
    public ResponseBo createOrder(@RequestBody @NotNull CreateOrderForm createOrderForm){
        return ResponseBo.ok(orderService.createOrderByCreateOrderForm(createOrderForm));
    }
    @GetMapping("getOrder")
    public ResponseBo getOrder(@RequestBody @NotNull QueryOrderForm queryOrderForm){
        return ResponseBo.ok(orderService.getOrderByQueryOrderForm(queryOrderForm));
    }

    @PatchMapping("updateOrder")
    public ResponseBo updateOrder(@RequestBody @NotNull UpdateOrderForm updateOrderForm){
        Order order = orderService.getOrderById(updateOrderForm.getOrderId());
        if (Objects.nonNull(order)){
            if (order.getStatus() == OrderStatus.Unfinished.name()){

            }
        }
        return ResponseBo.ok();
    }
}
